<?php
/**
 * Created by PhpStorm.
 * User: DongYao
 * Date: 2017/12/19
 * Time: 下午8:00
 */

namespace App\Tables\Expressions;


use Illuminate\Database\Query\Expression;

class GeoEntry extends Expression
{
    /**
     * The value of the expression.
     *
     * @var mixed
     */
    protected $value;

    /**
     * Create a new raw query expression.
     *
     * @param  mixed  $value
     */
    public function __construct($value)
    {
        $this->value = $value;
    }

    /**
     * Get the value of the expression.
     *
     * @return mixed
     */
    public function getValue()
    {
        return "ST_GeomFromText('POINT({$this->value['lat']} {$this->value['lng']})')";
    }

    /**
     * Get the value of the expression.
     *
     * @return string
     */
    public function __toString()
    {
        return (string) $this->getValue();
    }
}